package com.woniuxy.classdeans.service.impl;

import com.woniuxy.classdeans.mapper.AuditMapper;
import com.woniuxy.classdeans.repository.VideoRepository;
import com.woniuxy.classdeans.service.AuditService;
import com.woniuxy.commons.entity.Vedio;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AuditServiceImpl implements AuditService {
    @Autowired
    private AuditMapper auditMapper;
    @Autowired
    private VideoRepository videoRepository;
    @Autowired
    private ElasticsearchTemplate elasticsearchTemplate;
    @Override
    public List<Vedio> selectVedios() {
        List<Vedio> Vedio = auditMapper.selectVedios();
        System.out.println("**************************");
        System.out.println(Vedio);


        return Vedio;
    }

    @Transactional
    @Override
    public Vedio findByVid(Integer vid) {
        Vedio vedio = auditMapper.findByVid(vid);
        return vedio;
    }

    @Override
    @Transactional
    public Integer updateVideoAudit(Vedio vedio) {
        int result = auditMapper.updateVideoAudit(vedio);
        if (result != -1)
             vedio =findByVid(vedio.getVid());
        videoRepository.save(vedio);
        return result;
    }

}
